﻿Public Class Form1
    Dim formheight As Integer
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Clipboard.Clear()
        Clipboard.SetText(TextBox2.Text)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Clipboard.Clear()
        Clipboard.SetText(TextBox3.Text)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Clipboard.Clear()
        Clipboard.SetText(TextBox4.Text)
    End Sub

    Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label6.Click
        Dim Browser As Object
        Browser = CreateObject("InternetExplorer.Application")
        Browser.Visible = True
        Browser.Navigate("http://bbs.ngacn.cc/nuke.php?func=ucp&uid=322877")
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        formheight = Me.Height
        Me.Height = GroupBox2.Location.Y + 28
        Me.Text = Me.Text + "  " + Me.Tag
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        ProgressBar1.Visible = True
        ProgressBar1.Enabled = True
        Dim str(8) As String
        Dim i As Integer

        For i = 0 To 7
            str(i) = "NULL"
        Next

        readformgooglecode("http://wow-updatefiles-downolader.googlecode.com/svn/trunk/updates", str(0))
        If Me.Tag < str(0) Then
            MsgBox("本程序有新的版本：" + str(0) + "，您现在使用的版本是：" + Me.Tag + "。请先更新本程序再继续。即将为您打开浏览器访问官方下载站点。", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "新版本信息")
            Dim Browser As Object
            Browser = CreateObject("InternetExplorer.Application")
            Browser.Visible = True
            Browser.Navigate("http://code.google.com/p/wow-updatefiles-downolader/")
            End
        End If

        readformgooglecode("http://wow-updatefiles-downolader.googlecode.com/svn/trunk/DataFull.txt", str(1))
        localreplace(str(1))

        readformgooglecode("http://wow-updatefiles-downolader.googlecode.com/svn/trunk/latest_version.txt", str(2))
        TextBox1.Text = str(2)
        TextBox1.Text = Val(TextBox1.Text)

        readformgooglecode("http://wow-updatefiles-downolader.googlecode.com/svn/trunk/date.txt", str(3))
        Label8.Text = "最新版本资料已经更新，资料发布日期：" + str(3)

        readformgooglecode("http://wow-updatefiles-downolader.googlecode.com/svn/trunk/UpdatesFull.txt", str(4))
        localreplace(str(4))

        readformgooglecode("http://wow-updatefiles-downolader.googlecode.com/svn/trunk/notice.txt", str(5))
        localreplace(str(5))
        If str(5) <> "0" And Button5.Tag < 2 Then
            Form2.Label1.Text = str(5)
            Form2.Show()
        End If

        readformgooglecode("http://wow-updatefiles-downolader.googlecode.com/svn/trunk/LangFull.txt", str(6))
        localreplace(str(6))

        readformgooglecode("http://wow-updatefiles-downolader.googlecode.com/svn/trunk/tfill.txt", str(7))
        If ComboBox1.Text = "zhCN" Or ComboBox1.Text = "enCN" Or ComboBox1.Text = "zhTW" Or ComboBox1.Text = "enTW" Or ComboBox1.Text = "koKR" Then
            str(7) = Replace(str(7), "[LOCAL]", ComboBox1.Text.Substring(2))
        End If
        If ComboBox1.Text = "enUS" Or ComboBox1.Text = "esMX" Or ComboBox1.Text = "ptBR" Then
            str(7) = Replace(str(7), "[LOCAL]", "NA")
        End If
        If ComboBox1.Text = "enGB" Or ComboBox1.Text = "deDE" Or ComboBox1.Text = "esES" Or ComboBox1.Text = "frFR" Or ComboBox1.Text = "ptPT" Or ComboBox1.Text = "ruRU" Or ComboBox1.Text = "itIT" Then
            str(7) = Replace(str(7), "[LOCAL]", "EU")
        End If
        Button6.Text = str(7)


        For i = 0 To 7
            If str(i) = "NULL" Then
                MsgBox("版本资料获取错误！请检查网络连接是否通畅。程序无法继续执行，即将退出。", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "致命错误")
                End
            End If
        Next i

        Button5.Tag = Button5.Tag + 1
        Me.Height = formheight

        ProgressBar1.Visible = False
        ProgressBar1.Enabled = False

        If str(1) = "0" Then
            TextBox2.Text = "此文件尚未提供下载!"
            Button2.Enabled = False
        Else
            TextBox2.Text = str(1)
        End If
        Label3.Text = "放在游戏安装目录/Data文件夹中："

        If str(6) = "0" Then
            TextBox3.Text = "此文件尚未提供下载!"
            Button3.Enabled = False
        Else
            TextBox3.Text = str(6)
        End If
        Label4.Text = "放在游戏安装目录/Data/" + ComboBox1.Text + "文件夹中："

        If str(4) = "0" Then
            TextBox4.Text = "此文件尚未提供下载!"
            Button4.Enabled = False
        Else
            TextBox4.Text = str(4)
        End If
        Label5.Text = "放在游戏安装目录/Updates文件夹中："

    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If (ComboBox1.Text <> "(请选择)") Then
            Label8.Text = ""
            Me.Height = GroupBox3.Location.Y + 28
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form3.Show()
    End Sub

    Private Sub readformgooglecode(ByRef url As String, ByRef str As String)
        Dim myRequest = System.Net.WebRequest.Create(url)
        Dim hwr As System.Net.HttpWebResponse = CType(myRequest.GetResponse(), System.Net.HttpWebResponse)
        Dim sr As New System.IO.StreamReader(hwr.GetResponseStream(), System.Text.Encoding.Default)
        Dim str1 As String = sr.ReadToEnd()
        sr.Close()
        hwr.Close()
        str = str1
    End Sub

    Private Sub localreplace(ByRef str As String)
        str = Replace(str, "[LOCAL]", ComboBox1.Text)
    End Sub

    Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label7.Click
        Dim Browser As Object
        Browser = CreateObject("InternetExplorer.Application")
        Browser.Visible = True
        Browser.Navigate("http://code.google.com/p/wow-updatefiles-downolader/")
    End Sub
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Dim Browser As Object
        Browser = CreateObject("InternetExplorer.Application")
        Browser.Visible = True
        Browser.Navigate(Button6.Text)
    End Sub
End Class
